function Circle(x, y, r) {
    this.x = x;
    this.y = y;
    this.r = r;
    this.color = '#331175';

    this.lx = 0;
    this.ly = 0;
}

(function () {
    function area(b, x, y) {
        var dx = b.x - x;
        var dy = b.y - y;
        return Math.sqrt(dx * dx + dy * dy) <= b.r;
    }

    Circle.prototype.draw = function (ctx) {
        ctx.fillStyle = this.color;
        ctx.beginPath();
        ctx.arc(this.x, this.y, this.r, 0, 2 * Math.PI);
        ctx.fill();
    };

    Circle.prototype.mousedown = function (x, y) {
        var test = area(this, x, y);
        if (test) {
            this.lx = x;
            this.ly = y;
            this.pressed = true;
        }
        return test;
    };

    Circle.prototype.mousemove = function (x, y) {
        if (this.pressed) {
            this.x += x - this.lx;
            this.y += y - this.ly;
            this.lx = x;
            this.ly = y;
        }
    };

    Circle.prototype.mouseup = function (x, y) {
        var test = area(this, x, y);
        if (test) {
            this.pressed = false;
        }
        return test;
    };
})();